package com.bootmy.controller;

import com.bootmy.Service.DictService;
import com.bootmy.mapper.DictMapper;
import com.bootmy.model.Dict;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/Login")
@Controller
public class LoginController {

	private static final Logger log = Logger.getLogger(LoginController.class);

	@Resource
	public DictMapper dictMapper;
	@Resource
	DictService dictService;


	/**
	 * 直接使用Mapper
	 * @return
	 */
	@RequestMapping(value = "/index", produces = "text/html")
	public String routerListView() {
		try {
		Dict dict = dictMapper.selectByPrimaryKey(Long.valueOf(1));
		log.info("/Login/index方法   -- LoginController ------- id="+dict.getId());
		List<Dict> list = new ArrayList<>();
		list.get(2).getId();//异常
		} catch (Exception e) {
			log.error("异常具体信息"+e.getMessage(), e);
		}
		return "index";
	}
	/**
	 * 直接使用Mapper
	 * @return
	 */
	@RequestMapping(value = "/getAllUser")
	@ResponseBody
	public Map<String,Object> getAllUser() {
		Map<String,Object> resutl = new HashMap<>();
		resutl.put("code","100");
		resutl.put("user",dictMapper.findAllUser());
		return resutl;
	}
	/**
	 * Service中用Mapper
	 * @return
	 */
	@RequestMapping("/getAllUserService")
	@ResponseBody
	public Map<String,Object> getAllUserService(){
		Map<String,Object> resutl = new HashMap<>();
		resutl.put("code","100");
		resutl.put("user",dictService.findAllUser());
		return resutl;
	}

	/**
	 * Service中调用Dao方法，dao通过构造方法注入
	 * @return
	 */
	@RequestMapping("/getAllUserServiceDao")
	@ResponseBody
	public Map<String,Object> getAllUserServiceDao(){

		Map<String,Object> resutl = new HashMap<>();
		resutl.put("code","100");
		resutl.put("user",dictService.findAllUserDao());
		return resutl;
	}
    
}
